﻿/*=====================================================================
  
    File:      TabularDatabase.HelperFunctions.cs

    Summary:   This is the class that implements all  miscellanea functionality 
               needed in the project but not directly related to the Tabular Objects.
 
               Tabular Database Cmdlets (TabularDatabaseCmdlets) is sample code 
               to show and explain how to use the AMO to Tabular (AMO2Tabular)
               library to build a PowerShell library of cmdlets to manage 
               Tabular model objects. 
               The sample can be seen as a sample library of cmdlets
               with the necessary code to execute each particular 
               action or operation over a logical tabular object. 

    Authors:   JuanPablo Jofre (jpjofre@microsoft.com)
    Date:	   04-Apr-2012
  
    Change history:

    @TODO: 
  
-----------------------------------------------------------------------
  
    This file is part of the Microsoft SQL Server Code Samples.
    Copyright (C) Microsoft Corporation.  All rights reserved.
  
  This source code is intended only as a supplement to Microsoft
  Development Tools and/or on-line documentation.  
  
  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF 
  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  PARTICULAR PURPOSE.
  
==================================================================== */



using System;
using MicrosoftSql2012Samples.Amo2Tabular;
using AMO = Microsoft.AnalysisServices;

namespace MicrosoftSql2012Samples.TabularDatabaseCmdlet
{
    internal class TabularDatabaseHelperFunctions
    {
        internal static AMO.ProcessType? TryParseProcessType(string process)
        {
            AMO.ProcessType? processType = null;
            if (!process.IsNullOrEmptyOrWhitespace())
            {
                //  Validate process value is the right value, else throw TerminatingError
                if (string.Compare(process, "ProcessAdd", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessAdd;
                else if (string.Compare(process, "ProcessClear", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessClear;
                else if (string.Compare(process, "ProcessClearStructureOnly", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessClearStructureOnly;
                else if (string.Compare(process, "ProcessData", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessData;
                else if (string.Compare(process, "ProcessDefault", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessDefault;
                else if (string.Compare(process, "ProcessDefrag", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessDefrag;
                else if (string.Compare(process, "ProcessFull", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessFull;
                else if (string.Compare(process, "ProcessIndexes", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessIndexes;
                else if (string.Compare(process, "ProcessRecalc", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessRecalc;
                else if (string.Compare(process, "ProcessScriptCache", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessScriptCache;
                else if (string.Compare(process, "ProcessStructure", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessStructure;
                else if (string.Compare(process, "ProcessUpdate", StringComparison.OrdinalIgnoreCase) == 0)
                    processType = Microsoft.AnalysisServices.ProcessType.ProcessUpdate;
            }
            return processType;
        }

        internal static DataType TryParseDataType(string type)
        {
            DataType dataType = DataType.Unsupported;
            if (!type.IsNullOrEmptyOrWhitespace())
            {
                #region Whole Number
                //  -   Whole Number    <-- Int16, Int32, Int64, UInt16, UInt32, UInt64, Byte, SByte
                if (string.Compare(type, "Whole Number", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "WholeNumber", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "Whole", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "Integer", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "Int", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "Long", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "Int16", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "Int32", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "Int64", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "UInt16", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "UInt32", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "UInt64", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "Byte", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                else if (string.Compare(type, "SByte", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.WholeNumber;
                #endregion
                #region Decimal
                //  -   Decimal         <-- Single, Double, Decimal
                else if (string.Compare(type, "Decimal", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Decimal;
                else if (string.Compare(type, "Single", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Decimal;
                else if (string.Compare(type, "Double", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Decimal;
                #endregion
                #region Currency
                //  -   Currency
                else if (string.Compare(type, "Currency", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Currency;
                #endregion
                #region YesNo
                //  -   YesNo           <-- Boolean
                else if (string.Compare(type, "YesNo", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.YesNo;
                else if (string.Compare(type, "Boolean", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.YesNo;
                else if (string.Compare(type, "bool", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.YesNo;
                #endregion
                #region Date
                //  -   Date            <-- Date
                else if (string.Compare(type, "Date", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Date;
                else if (string.Compare(type, "Time", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Date;
                else if (string.Compare(type, "DateTime", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Date;
                #endregion
                #region Image
                //  -   Image          <-- Byte[]
                else if (string.Compare(type, "Image", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Image;
                else if (string.Compare(type, "BLOB", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Image;
                #endregion
                #region Text
                //  -   Text          <-- String, Guid
                else if (string.Compare(type, "String", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Text;
                else if (string.Compare(type, "Text", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Text;
                else if (string.Compare(type, "Guid", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Text;
                #endregion
                #region Default
                //  -   Default
                else if (string.Compare(type, "Default", StringComparison.OrdinalIgnoreCase) == 0)
                    dataType = DataType.Default;
                #endregion
            }

            return dataType;
        }
    }
            

 

}
